'''
https://leetcode.cn/problems/web-crawler/?envType=study-plan-v2&envId=premium-algo-100
'''

from typing import List

# """
# This is HtmlParser's API interface.
# You should not implement it, or speculate about its implementation
# """
class HtmlParser(object):
   def getUrls(self, url):
       """
       :type url: str
       :rtype List[str]
       """
       return []

from urllib.parse import urlparse
class Solution:
    def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:
        domain = urlparse(startUrl).netloc
        def is_same_host(url:str):
            parse_res = urlparse(url)
            return parse_res.netloc == domain
        visited = set()
        res = []
        def f(u):
            if u in visited:
                return
            if not is_same_host(u):
                return
            visited.add(u)
            res.append(u)
            for v in htmlParser.getUrls(u):
                f(v)
        f(startUrl)
        return res





startUrl = "http://news.yahoo.com/news/topics/"
parse_result = urlparse(startUrl)
print(parse_result)
print(parse_result.scheme)
print(parse_result.netloc)
print(parse_result.path)
